<template>
	<view class="newwenjuan">
		<headertop title="记录" str="orderlist" str1="oridei" :back1="back1"></headertop>
		<view class="newwenjuanback">

		</view>
		<view class="" :style="{'margin-top':statusBarHeight+'px','width':'100%','height':barHeight+'px'}">
		</view>
		<view class="wenjuanlist">
			<view class="msgicon" v-if="!list.length">
				<image :src="_static('/images/wxnone.png')" mode="widthFix">
				</image>
				<view class="msgtext">
					暂无内容
				</view>
			</view>
			<view class="itembox" v-for="(item,index) in list" :key="index">
				<view class="centertext">
					<view class="t1">
						{{item['result']}}
					</view>
					<view class="texts">
						{{formattedDate(item.createtime*1000)}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import headertop from '@/components/header.vue'
	import {
		_static
	} from '@/ulm/utils/url.js'
	import {
		onPageScroll,
		onLoad,
		onShow,
		onReachBottom
	} from "@dcloudio/uni-app";
	import ulm, {
		$api
	} from '@/ulm';
	import {
		ref,
		reactive,
		onMounted
	} from 'vue'
	const statusBarHeight = ref('')
	const barHeight = ref('')
	const back1 = ref('')
	const list = ref([])
	const total = ref(0)
	const formData = reactive({
		page: 1,
		list_rows: 10
	})
	onMounted(() => {
		statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight
		const {
			top,
			height
		} = wx.getMenuButtonBoundingClientRect();
		barHeight.value = height ? height + (top - statusBarHeight.value) * 2 : 38;
	})
	onReachBottom(() => {
		if (total.value > list.value.length) {
			formData['page']++
			initwenjuan()
		}
	})
	onPageScroll((e) => {

		if (e.scrollTop > 100) {
			back1.value = '#81D6FF'
		} else {
			back1.value = ''
		}

	})
	onLoad(() => {
		initwenjuan()
	})

	function padStart(n) {
		return n.toString().padStart(2, 0)
	}

	function formattedDate(time) {
		let date = new Date(time)
		let Y = date.getFullYear() + '-'
		let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
		let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
		let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
		let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes())
		let s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
		return Y + M + D + h + m
	}
	async function initwenjuan() {
		const res = await $api.constitutionrecord(formData)
		if (res.code == 1) {
			list.value.push(...res.data.data)
			total.value = res.data.total
		}
	}

	function gopage(item) {
		uni.navigateTo({
			url: '/sub_index/index/wenjuan?titlestr=' + item['title'] + '&typestr=最新问卷&id=' + item.id
		})
	}
</script>

<style lang="scss">
	.itembox {
		width: 686rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 10rpx 0rpx rgba(0, 0, 0, 0.05);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		overflow: hidden;
		margin: auto;
		margin-bottom: 28rpx;
		height: 208rpx;

		.centertext {
			width: 632rpx;
			margin: auto;
			margin-top: 32rpx;
			overflow: hidden;

			.t1 {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #1D2129;
				overflow: hidden;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				-ms-text-overflow: ellipsis;
				text-overflow: ellipsis;
				height: 80rpx;
			}

			.texts {
				width: 100%;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #4E5969;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				margin-top: 28rpx;
				margin-bottom: 28rpx;
			}

			.date {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #4E5969;
				margin-top: 24rpx;
			}
		}
	}

	.msgicon {
		width: 608rpx;
		margin: 100rpx auto;
		overflow: hidden;

		.msgtext {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #86909C;
			text-align: center;
			width: 100%;
			margin-top: 30rpx;
		}

		image {
			width: 608rpx;
		}
	}

	page {
		background: #F7F8FA;
	}

	.newwenjuan {
		width: 100%;
		overflow: hidden;
		position: relative;

		.newwenjuanback {
			width: 100%;
			height: 446rpx;
			background: linear-gradient(180deg, #CAEEFF 71%, rgba(240, 250, 255, 0) 100%);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			position: absolute;
			z-index: -1;
		}

		.wenjuanlist {
			width: 686rpx;
			margin: auto;
			margin-top: 28rpx;
			overflow: hidden;

			.wenjuanitem {
				width: 100%;
				border-radius: 20rpx;
				overflow: hidden;
				margin-bottom: 24rpx;

				.timg {
					width: 100%;
					height: 264rpx;
				}

				.tt {
					width: 100%;
					background: #FFFFFF;
					padding: 16rpx 0;

					.text {
						width: 95%;
						margin: auto;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 28rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						color: #1D2129;
					}
				}
			}
		}
	}
</style>